package pt.utl.ist.ginger3d.domain.types;

import java.util.Map;

import pt.utl.ist.ginger3d.BufferedRandomAccessFile;

public class DerivedType implements IBlockType {
	
	IBlockType baseType;
	Map<String, String> properties;
	
	public DerivedType(IBlockType baseType, Map<String, String> properties) {
		
		this.baseType = baseType;
		this.properties = properties;
		
		Map<String, String> baseDefaultProperties = baseType.getDefaultProperties();
		if(baseDefaultProperties == null) {
			return;
		}
		// add inexistent base default properties
		for(Map.Entry<String, String> entry : baseDefaultProperties.entrySet()) {
			if(!properties.containsKey(entry.getKey())) {
				properties.put(entry.getKey(), entry.getValue());
			}
		}
	}

	public String[] getHandledTypes() {
		return baseType.getHandledTypes();
	}

	public String[] getRequiredProperties(String typeId) {
		return baseType.getRequiredProperties(typeId);
	}

	public Object readValue(BufferedRandomAccessFile file, String typeId, Map<String, String> properties) {
		return baseType.readValue(file, typeId, properties);
	}

	public Object readValueAsString(BufferedRandomAccessFile file, String typeId, Map<String, String> properties) {
		return baseType.readValueAsString(file, typeId, properties);
	}

	public Map<String, String> getDefaultProperties() {
		return properties;
	}

}
